var ligerGrid;

$(function() {
			var options = {
				queryKey : queryKey,
				pageSize : 30,
				gridWidth : null,
				gridHeight : 580,
				showIdx : false,
				// init param for groove.query, property querykey is reserved,
				// property method is reserved,
				// init param for groove.view, property id is reserved
				gridRender : function(grid) {
					ligerGrid = grid;
				}
			};
			var gridPanel = new $.grooveQuery(options);

			$("#pageloading").hide();
		});

function defaultFnRender(rowdata, rowindex, value, column) {
	if (column.name == "LA_STATUS") {
		if (value == -1) {
			return "审核未通过";
		} else if (value == 0) {
			return "待审核";
		} else if (value == 1) {
			return "审核通过";
		} else if (value == 2) {
			return "合同生成";
		}
	} else if (column.name == "LA_DATE" || column.name == "LA_AUDITTIME") {
		return formatDate(value);
	} else if (column.name == "SP") {
		if (rowdata["LA_STATUS"] == 0) {
			return "<a href=\"javascript:void(0);\" onclick=\"audit('"
					+ rowdata["PK_ID"] + "', '" + rowdata["LA_LOANPRODUCTID"]
					+ "')\">贷款审批</a>";
		} else if (rowdata["LA_STATUS"] == 1) {
			return "<a href=\"javascript:void(0);\" onclick=\"contract('"
					+ rowdata["PK_ID"] + "', '" + rowdata["LA_LOANPRODUCTID"]
					+ "')\">贷款合同办理</a>";
		} else if (rowdata["LA_STATUS"] == 2) {
			return "<a href=\"javascript:void(0);\" onclick=\"viewContract('"
					+ rowdata["PK_ID"] + "', '" + rowdata["LA_LOANPRODUCTID"]
					+ "')\">查阅</a>";
		}
	}
	return value;
}

function audit(id) {
	document.location = context + "/site/creditOrganization/16-1.jsp?id=" + id;
}

function contract(id, fpid) {
	document.location = context + "/site/creditOrganization/17-1.jsp?id=" + id;
}

var editDialog;

function viewContract(id) {
	grooveTableSelectorI({
				id : id,
				columnName : "FC_APPLYID",
				tableName : "financialContract",
				handleType : "single",
				initFunc : function(data) {
					var jsonparams = {
						id : data.PK_ID,
						primaryTable : "financialContract"
					}

					new $.grooveViewPreII(jsonparams, "viewcreditcontract", {
								formID : "formID",
								mode : "view",
								beforecall : function() {
									$("#target1").css("display", "none");
								},
								aftercall : function() {
									editDialog.hide();

									ligerGrid.reload();
								},
								rendercall : function(selfFunc, validator,
										validators, viewConfig) {
									editDialog = $.ligerDialog.open({
												title : "贷款合同信息预览窗口",
												target : $("#target1"),
												height : 500,
												width : 800,
												buttons : [{
													text : '关闭',
													onclick : function(item,
															dialog) {
														dialog.hide();
													}
												}],
												isResize : true
											});
								}
							});
				}
			});
}